package com.bytz.modules.cms.product.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytz.modules.cms.product.entity.ProductDiscountCategory;
import com.bytz.modules.cms.product.mapper.ProductDiscountCategoryMapper;
import com.bytz.modules.cms.product.service.IProductDiscountCategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 莱宝CMS—产品管理—产品优惠分类表 服务实现类
 * </p>
 *
 * @author KyleWang
 * @since 2022-10-10
 */
@Service
public class ProductDiscountCategoryServiceImpl extends ServiceImpl<ProductDiscountCategoryMapper, ProductDiscountCategory> implements IProductDiscountCategoryService {

    @Override
    public List<ProductDiscountCategory> getByIds(List<String> ids) {

        if (CollectionUtil.isEmpty(ids)) {
            return new ArrayList<>();
        }

        return lambdaQuery().in(ProductDiscountCategory::getId, ids).list();
    }

    @Override
    public List<ProductDiscountCategory> getByNamesAndProductLine(Collection<String> categoryName, String productLineId) {

        if (CollectionUtil.isEmpty(categoryName)) {
            return new ArrayList<>();
        }

        LambdaQueryChainWrapper<ProductDiscountCategory> wrapper = lambdaQuery().in(ProductDiscountCategory::getCategoryName, categoryName);

        if (StringUtils.isNotBlank(productLineId)) {
            wrapper.eq(ProductDiscountCategory::getProductLineId, productLineId);
        }

        return wrapper.list();
    }
}
